package base.Stream流;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collectors;

public class 终结方法 {
    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张无忌-男-18","周芷若-女-17","赵敏-女-18","张三丰-男-19");

        String[] sArry = list.stream().toArray(new IntFunction<String[]>() {
            @Override
            public String[] apply(int value) {
                return new String[value];
            }
        });
        System.out.println(Arrays.toString(sArry));

        list.stream().collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) { //key
                return s.split("-")[0];
            }
        }, new Function<String, Integer>() {
            @Override
            public Integer apply(String s) { //value
                return Integer.parseInt(s.split("-")[2]);
            }
        }));

        //lambda表达式：
        Map<String, String> map = list.stream().collect(Collectors.toMap(
                s -> s.split("-")[0],
                s -> s.split("-")[2]
        ));
        System.out.println(map);
    }

}
